<?php
/**
 * 用户管理控制器
 */
class UserController extends  IsLoginController{
	/**
	 * 前台用户组
	 */
	public function index(){
		$user = M('user')->where("is_admin=0")->all();
		$this->assign('user',$user);
		$this->display();
	}
	/**
	 * 后台用户组
	 */
	public function admin(){
		$admin = M('user')->where("is_admin=1")->all();
		$this->assign('admin',$admin);
		$this->display();
	}
	/**
	 * 删除用户组
	 */
	public function del(){
		if(IS_POST){
		$uid = Q('post.uid');p($uid);die;
		 foreach($uid as $v){
			$v = (int)$v;
			M('user')->where("uid='{$v}'")->del();
		 }
			$this->success('删除成功');
		}
	}
	
	//删除后台用户组
	public function delAdmin(){
		if(IS_GET){
			$uid = Q('get.uid');
			M('user')->where("uid='{$uid}'")->del();
			$this->success('删除成功');
		}

		
	}
	
	
	/**
	 * 编辑用户组
	 */
	 public function edit(){
	 	//查询用户信息
	 	$uid = Q('get.uid');
		$user = M('user')->where("uid='{$uid}' ")->find();
		$this->assign('user',$user);
		if(IS_POST){
					$uid = Q('post.uid');
				//检测用户名密码是否更改  如果更改就记修改 如果没改 赋原值
				if(Q('post.password') != ''){
					$password =Q('post.password') ;
					if($password == $user['password']){
						$password = $user['password'];
					}else{
						$password = md5(Q('post.password'));
					}
				}else{
					$this->error(‘用户密码不能为空’);
				}
				$_POST['password'] = $password;
					M('user')->where("uid='{$uid}'")->update($_POST);
						$this->success('修改成功');
				}
			 $this->display();
	 }

}
